home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 4
/
FM Towns Free Software Collection 4 - Disc 1.iso
/
t_os
/
tie
/
src
/
mos.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-10-18
|
2KB
|
106 lines
#include <stdio.h>
#include <stdlib.h>
#define TRUE 1
#define FALSE 0
#define ERROR (-1)
typedef unsigned char u_char ;
typedef struct
{
u_char p[ 64 ][ 4 ] ;
} data ;
extern int dump( int num, data buf[] ) ;
void main( int argc, char *argv[] )
{
FILE *fp ;
char *path ;
data buf[2] ;
int i ;
if( argc == 1 )
path = "moscsr.icn" ;
else
path = argv[ 1 ] ;
if( ( fp = fopen( path, "rb" ) ) == NULL )
{
puts( "can't open" ) ;
exit( 1 ) ;
}
for( i = 0 ; i < 64 ; i ++ )
{
fread( (char *)buf, 1, 512, fp ) ;
if( dump( i, buf ) == ERROR )
break ;
}
fclose( fp ) ;
}
static int dump( int num, data buf[] )
{
int i, j, k, pack ;
int x = -1, y = -1, lf = FALSE ;
data *p ;
u_char cmp[2] = { '\0', '\xFF' } ;
for( i = 0 ; i < 2 ; i ++ )
{
p = &buf[ i ] ;
for( j = 0 ; j < 32 ; j ++ )
{
for( k = 0 ; k < 4 ; k ++ )
{
if( p -> p[j][k] != cmp[i] )
{
if( x < k ) x = k ;
if( y < j ) y = j ;
}
}
}
if( x == -1 && y == -1 )
return( ERROR ) ;
}
printf( " { 0,0, %d,%d, /* %03d */\n", x+1, y+1, num ) ;
switch( x )
{
case 0: pack = 10 ; break ;
case 1: pack = 6 ; break ;
case 2: pack = 4 ; break ;
case 3: pack = 3 ; break ;
}
for( i = 0 ; i < 2 ; i ++ )
{
p = &buf[ i ] ;
lf = TRUE ;
for( j = 0 ; j <= y ; j ++ )
{
printf( lf == TRUE ? " " : " " ) ;
lf = FALSE ;
for( k = 0 ; k <= x ; k ++ )
printf( "0x%02X,", p -> p[j][k] ) ;
if( j % pack == pack-1 )
lf = TRUE, printf( "\n" ) ;
}
if( i == 1 )
printf( " }," ) ;
if( lf != TRUE )
printf( "\n" ) ;
}
printf( "\n" ) ;
return( ERROR+1 ) ;
}